//
//  XMLDefaultDelegate.m
//  Seizure
//
//  Created by student on 2/28/12.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import "XMLDefaultDelegate.h"

@implementation XMLDefaultDelegate
@synthesize currentElementValue;
@synthesize result;

NSString *captureElement = @"title";
bool recording = NO;

// initalize things
- (id)init {
    if (self = [super init]){
        currentElementValue = [[NSMutableString alloc] init ];
        result = [[NSString alloc] initWithString:@""];
    }
    return self;
}

//- (void)parser:(NSXMLParser *) parser
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI
 qualifiedName:(NSString *)qualifiedName attributes:(NSDictionary *)attributeDict {
    
    if ([elementName isEqualToString:captureElement]){
        recording = YES;
    }
    
}

- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI
 qualifiedName:(NSString *)qName {
    
    if ([elementName isEqualToString:captureElement]){
        recording = NO;
        [currentElementValue stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
        result = currentElementValue;

    }
}

- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
    if (recording)
    {
        [currentElementValue appendString:string];
    }
}
@end
